package main.examination.NetEase;

import java.util.Scanner;

/** 快递员 */
public class ex3 {
    private static int res;

    /** 超时 */
    public static void main(String[] args) {
        res = 0;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean[][] graph = new boolean[n][n];
        for (int i = 0; i <= n - 2; i++) {
            int x = sc.nextInt();
            graph[i + 1][x] = true;
            graph[x][i + 1] = true;
        }
        boolean[] isVisited = new boolean[n];
        isVisited[0] = true;
        solution(0, 0, n, k, isVisited, graph);
        System.out.println(res + 1);
    }

    private static void solution(
            int start, int cnt, int n, int k, boolean[] isVisited, boolean[][] graph) {
        if (k == 0) {
            res = Math.max(res, cnt);
            return;
        }
        boolean[] next = graph[start];
        for (int i = 0; i < n; i++) {
            if (next[i]) {
                boolean flag = false;
                if (!isVisited[i]) {
                    ++cnt;
                    flag = true;
                    isVisited[i] = true;
                }
                solution(i, cnt, n, k - 1, isVisited, graph);
                if (flag) {
                    --cnt;
                    isVisited[i] = false;
                }
            }
        }
    }
}
